package me.aip.mov.controller;

import me.aip.mov.annotation.GlobalResult;
import me.aip.mov.annotation.PassToken;
import me.aip.mov.entity.ChatFriends;
import me.aip.mov.entity.ChatMsg;
import me.aip.mov.entity.Message;
import me.aip.mov.entity.UserInfo;
import me.aip.mov.response.ResponseResult;
import me.aip.mov.service.IChatFriendsService;
import me.aip.mov.service.IChatMsgService;
import me.aip.mov.service.ILoginService;
import me.aip.mov.service.IUserInfoService;
import me.aip.mov.util.RequestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")
@GlobalResult
public class UserInfoController {
    @Autowired
   IUserInfoService userInfoService;

    @GetMapping("/getUserInfo")
    public UserInfo getUserInfo(HttpServletRequest request) {
        String userId = RequestUtil.getUserId(request);
        UserInfo userInfo = userInfoService.getById(userId);
        userInfo.setPassword(null);
        userInfo.setSalt(null);
        return userInfo;
    }

    @GetMapping("/findKf")
    public UserInfo findKf(HttpServletRequest request) {
        return userInfoService.findKf();
    }


    @GetMapping("/getPromoCode")
    @PassToken
    public ResponseResult getPromoCode(HttpServletRequest request) {
        String userId = RequestUtil.getUserId(request);
        String qrCode = userInfoService.getPromoCode(userId);
        return ResponseResult.success(qrCode);
    }
    @PostMapping("/updateUser")
    public void updateUser(HttpServletRequest request,@RequestBody UserInfo user) {
        String userId = RequestUtil.getUserId(request);
        user.setUserId(userId);
        userInfoService.updateById(user);
    }

}
